package MySemaphore;

import java.util.concurrent.Semaphore;

public class Fun {
    private final Semaphore semaphore = new Semaphore(1);
    private long count = 0;
    public void add() throws InterruptedException {
        for (int i = 0; i < 500; i++) {
            semaphore.acquire();
            try {
                System.out.println(++count);
            }finally {
                semaphore.release();
            }
        }
    }

}
